package com.ctshk.rpc.system.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.system.entity.SysSupplierOrderMsg;
import com.ctshk.rpc.system.entity.SysSupplierOrderMsgUser;
import com.ctshk.rpc.system.mapper.provider.SysSupplierOrderMsgProvider;
import com.ctshk.rpc.system.req.SysSupplierOrderMsgPageReq;

/**
 * <p>assignmentMgtList
 *  分配管理 Mapper 接口
 * </p>
 *
 * @author 姜斌文
 * @since 2021-03-30
 */
public interface SysAssignmentMgtMapper extends BaseMapper<SysSupplierOrderMsg> {

    @SelectProvider(type = SysSupplierOrderMsgProvider.class, method = "assignmentMgtList")
    IPage<SysSupplierOrderMsg> assignmentMgtList(IPage<SysSupplierOrderMsg> page, SysSupplierOrderMsgPageReq sysSupplierOrderMsgPageReq);

    /**
     * 根据类型获取分配对象数据
     * @param reuleId
     * @return List<SysSupplierOrderMsgUser>
     */
    @Select("select t.id, t.type, t.rule_type ,t.message_type, t.charge_person_id, t.charge_person_name,"
    		+ "(SELECT group_concat(u.user_id) FROM t_supplier_order_message_rule_user u WHERE u.rule_id = t.id )AS \"groupPersonIds\","
    		+ "(SELECT group_concat(u.user_name) FROM t_supplier_order_message_rule_user u WHERE u.rule_id = t.id )AS \"groupPersonNames\","
    		+ "(SELECT group_concat(u.id) FROM t_supplier_order_message_rule_user u WHERE u.rule_id = t.id )AS \"groupRuleUserIds\""
    		+ "FROM t_supplier_order_message_rule t "
    		+ "WHERE t.`status` = 0 AND t.is_deleted = 0 AND t.type = #{type}")
    List<SysSupplierOrderMsg> selectValidDataByType(@Param("type") long type);
}
